﻿namespace WMS6.Web.Analytics
{
    using System;
    using System.Data;
    using System.Web.UI;
    using System.Web.UI.HtmlControls;
    using System.Web.UI.WebControls;
    using WMS6.Web;
    using WMS6.Web.CustomsServiceRef;
    using WMS6.Web.UserControls;

    public class DeclarationsItemNoBlanaceRptList : BasePage
    {
        protected Button btnExport;
        protected Button btnList;
        protected Button btnRefresh;
        protected Button btnReSearch;
        protected Button btnSearch;
        protected HtmlForm F15541;
        protected GridView gvDeclarationsItemNoBlanaceRptList;
        protected HtmlInputHidden hdnActionID;
        protected HtmlInputHidden hdnFrom;
        protected HtmlInputHidden hdnShowLot;
        protected HtmlHead Head1;
        protected Label lblDeclarationsItemNoBlanaceRptList;
        protected Label lblMsg;
        protected Label lblTotalBeginningQty;
        protected Label lblTotalBeginningQtyText;
        protected Label lblTotalCurrentIssueInboundQty;
        protected Label lblTotalCurrentIssueInboundQtyText;
        protected Label lblTotalCurrentIssueOutBoundQty;
        protected Label lblTotalCurrentIssueOutBoundQtyText;
        protected Label lblTotalQty;
        protected Label lblTotalQtyText;
        protected HtmlLink mycss;
        protected Pager PagerFooter;
        protected ScriptManager ScriptManager1;
        private decimal TotalBeginningQty;
        private decimal TotalCurrentIssueInboundQty;
        private decimal TotalCurrentIssueOutBoundQty;
        private decimal TotalQty;
        protected UpdatePanel up1;

        public void BindData2DeclarationsItemNoBlanaceRpt(DeclarationsItemNoBlanaceRptQueryEntity declarationsItemNoBlanaceRptQueryEntity)
        {
            this.PagerFooter.CurrentPage = int.Parse(declarationsItemNoBlanaceRptQueryEntity.CurrentPage);
            DataSet ds = CustomsServiceClientProxy.GetInstance().GetDeclarationsItemNoBlanaceRptDataSet(declarationsItemNoBlanaceRptQueryEntity);
            base.BindData2GridView(this.gvDeclarationsItemNoBlanaceRptList, ds);
            if ((ds != null) && (ds.Tables.Count > 1))
            {
                this.PagerFooter.PageInfo = ds.Tables[1].Rows[0]["CurrentPage"].ToString() + " / " + ds.Tables[1].Rows[0]["TotalPagesCount"].ToString() + "&nbsp;&nbsp;&nbsp;共: " + ds.Tables[1].Rows[0]["TotalRecordsCount"].ToString();
                this.PagerFooter.TotalPages = int.Parse(ds.Tables[1].Rows[0]["TotalPagesCount"].ToString());
            }
        }

        protected void btnExport_Click(object sender, EventArgs e)
        {
            DeclarationsItemNoBlanaceRptQueryEntity declarationsItemNoBlanaceRptQueryEntity = this.GetDeclarationsItemNoBlanaceRptQueryEntity();
            declarationsItemNoBlanaceRptQueryEntity.IsGetAll = true;
            this.hdnActionID.Value = "EXPORT";
            string currentPageIndex = declarationsItemNoBlanaceRptQueryEntity.CurrentPage;
            declarationsItemNoBlanaceRptQueryEntity.CurrentPage = "0";
            try
            {
                using (DataSet ds = CustomsServiceClientProxy.GetInstance().GetDeclarationsItemNoBlanaceRptDataSet(declarationsItemNoBlanaceRptQueryEntity))
                {
                    base.Export2Excel(" DeclarationsItemNoBlanaceRpt.xls", "15541", this.gvDeclarationsItemNoBlanaceRptList, ds);
                }
            }
            finally
            {
                declarationsItemNoBlanaceRptQueryEntity.IsGetAll = false;
                declarationsItemNoBlanaceRptQueryEntity.CurrentPage = currentPageIndex;
                this.SetDeclarationsItemNoBlanaceRptQueryEntity(declarationsItemNoBlanaceRptQueryEntity);
            }
        }

        protected void btnFirst_Click(object sender, EventArgs e)
        {
            DeclarationsItemNoBlanaceRptQueryEntity declarationsItemNoBlanaceRptQueryEntity = this.GetDeclarationsItemNoBlanaceRptQueryEntity();
            declarationsItemNoBlanaceRptQueryEntity.CurrentPage = "0";
            this.BindData2DeclarationsItemNoBlanaceRpt(declarationsItemNoBlanaceRptQueryEntity);
        }

        protected void btnLast_Click(object sender, EventArgs e)
        {
            DeclarationsItemNoBlanaceRptQueryEntity declarationsItemNoBlanaceRptQueryEntity = this.GetDeclarationsItemNoBlanaceRptQueryEntity();
            declarationsItemNoBlanaceRptQueryEntity.CurrentPage = (this.PagerFooter.TotalPages - 1).ToString();
            this.BindData2DeclarationsItemNoBlanaceRpt(declarationsItemNoBlanaceRptQueryEntity);
        }

        protected void btnList_Click(object sender, EventArgs e)
        {
            DeclarationsItemNoBlanaceRptQueryEntity declarationsItemNoBlanaceRptQueryEntity = this.GetDeclarationsItemNoBlanaceRptQueryEntity();
            declarationsItemNoBlanaceRptQueryEntity.ItemNoID = "";
            declarationsItemNoBlanaceRptQueryEntity.StartTime = "";
            declarationsItemNoBlanaceRptQueryEntity.EndTime = "";
            this.BindData2DeclarationsItemNoBlanaceRpt(declarationsItemNoBlanaceRptQueryEntity);
        }

        protected void btnNext_Click(object sender, EventArgs e)
        {
            DeclarationsItemNoBlanaceRptQueryEntity declarationsItemNoBlanaceRptQueryEntity = this.GetDeclarationsItemNoBlanaceRptQueryEntity();
            if (int.Parse(declarationsItemNoBlanaceRptQueryEntity.CurrentPage) < (this.PagerFooter.TotalPages - 1))
            {
                declarationsItemNoBlanaceRptQueryEntity.CurrentPage = (int.Parse(declarationsItemNoBlanaceRptQueryEntity.CurrentPage) + 1).ToString();
                this.BindData2DeclarationsItemNoBlanaceRpt(declarationsItemNoBlanaceRptQueryEntity);
            }
        }

        protected void btnPrevious_Click(object sender, EventArgs e)
        {
            DeclarationsItemNoBlanaceRptQueryEntity declarationsItemNoBlanaceRptQueryEntity = this.GetDeclarationsItemNoBlanaceRptQueryEntity();
            if (int.Parse(declarationsItemNoBlanaceRptQueryEntity.CurrentPage) > 0)
            {
                declarationsItemNoBlanaceRptQueryEntity.CurrentPage = (int.Parse(declarationsItemNoBlanaceRptQueryEntity.CurrentPage) - 1).ToString();
                this.BindData2DeclarationsItemNoBlanaceRpt(declarationsItemNoBlanaceRptQueryEntity);
            }
        }

        protected void btnRefresh_Click(object sender, EventArgs e)
        {
            DeclarationsItemNoBlanaceRptQueryEntity declarationsItemNoBlanaceRptQueryEntity = this.GetDeclarationsItemNoBlanaceRptQueryEntity();
            this.BindData2DeclarationsItemNoBlanaceRpt(declarationsItemNoBlanaceRptQueryEntity);
        }

        private DeclarationsItemNoBlanaceRptQueryEntity GetDeclarationsItemNoBlanaceRptQueryEntity()
        {
            return (base.PageQueryEntitySession as DeclarationsItemNoBlanaceRptQueryEntity);
        }

        protected void GoTo_Click(object sender, EventArgs e)
        {
            if (!string.IsNullOrEmpty(((TextBox) this.PagerFooter.FindControl("txtGo2Page")).Text.Trim()))
            {
                DeclarationsItemNoBlanaceRptQueryEntity declarationsItemNoBlanaceRptQueryEntity = this.GetDeclarationsItemNoBlanaceRptQueryEntity();
                declarationsItemNoBlanaceRptQueryEntity.CurrentPage = this.PagerFooter.GoToPage.ToString();
                this.BindData2DeclarationsItemNoBlanaceRpt(declarationsItemNoBlanaceRptQueryEntity);
            }
        }

        protected void gvDeclarationsItemNoBlanaceRptList_Init(object sender, EventArgs e)
        {
            base.InitDetailGridView("F15541", this.gvDeclarationsItemNoBlanaceRptList);
        }

        protected void gvDeclarationsItemNoBlanaceRptList_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                e.Row.Cells[0].Text = (((this.PagerFooter.CurrentPage * this.PagerFooter.PageSize) + e.Row.RowIndex) + 1).ToString();
                e.Row.Attributes.Add("onmouseout", "GridViewRowMouseout(this);");
                e.Row.Attributes.Add("onmouseover", "GridViewRowMouseover(this);");
                ((CheckBox) e.Row.FindControl("chbSelect")).Attributes.Add("onclick", "GridViewCheckBoxClick('" + e.Row.ClientID + "')");
                e.Row.Attributes.Add("ondblclick", "JavaScript:document.getElementById('" + ((CheckBox) e.Row.FindControl("chbSelect")).ClientID + "').click();");
                if (this.hdnActionID.Value != "EXPORT")
                {
                    base.SetGridViewLongTextLabel((Label) e.Row.FindControl("lblItemNoDescr"));
                }
                if (((Label) e.Row.FindControl("lblBeginningQty")) != null)
                {
                    this.TotalBeginningQty += decimal.Parse((((Label) e.Row.FindControl("lblBeginningQty")).Text != "") ? ((Label) e.Row.FindControl("lblBeginningQty")).Text : "0");
                }
                if (((Label) e.Row.FindControl("lblCurrentIssueInboundQty")) != null)
                {
                    this.TotalCurrentIssueInboundQty += decimal.Parse((((Label) e.Row.FindControl("lblCurrentIssueInboundQty")).Text != "") ? ((Label) e.Row.FindControl("lblCurrentIssueInboundQty")).Text : "0");
                }
                if (((Label) e.Row.FindControl("lblCurrentIssueOutBoundQty")) != null)
                {
                    this.TotalCurrentIssueOutBoundQty += decimal.Parse((((Label) e.Row.FindControl("lblCurrentIssueOutBoundQty")).Text != "") ? ((Label) e.Row.FindControl("lblCurrentIssueOutBoundQty")).Text : "0");
                }
                if (((Label) e.Row.FindControl("lblTotalQty")) != null)
                {
                    this.TotalQty += decimal.Parse((((Label) e.Row.FindControl("lblTotalQty")).Text != "") ? ((Label) e.Row.FindControl("lblTotalQty")).Text : "0");
                }
            }
            if (e.Row.RowType == DataControlRowType.Footer)
            {
                this.lblTotalBeginningQtyText.Text = base.GetPreferenceDigit(this.TotalBeginningQty);
                this.lblTotalCurrentIssueInboundQtyText.Text = base.GetPreferenceDigit(this.TotalCurrentIssueInboundQty);
                this.lblTotalCurrentIssueOutBoundQtyText.Text = base.GetPreferenceDigit(this.TotalCurrentIssueOutBoundQty);
                this.lblTotalQtyText.Text = base.GetPreferenceDigit(this.TotalQty);
            }
        }

        protected void gvDeclarationsItemNoBlanaceRptList_Sorting(object sender, GridViewSortEventArgs e)
        {
            try
            {
                DeclarationsItemNoBlanaceRptQueryEntity declarationsItemNoBlanaceRptQueryEntity = this.GetDeclarationsItemNoBlanaceRptQueryEntity();
                declarationsItemNoBlanaceRptQueryEntity.SortField = e.SortExpression;
                if ((declarationsItemNoBlanaceRptQueryEntity.SortDirection == "ASC") || (declarationsItemNoBlanaceRptQueryEntity.SortDirection.Trim() == ""))
                {
                    declarationsItemNoBlanaceRptQueryEntity.SortDirection = "DESC";
                }
                else if (declarationsItemNoBlanaceRptQueryEntity.SortDirection == "DESC")
                {
                    declarationsItemNoBlanaceRptQueryEntity.SortDirection = "ASC";
                }
                this.BindData2DeclarationsItemNoBlanaceRpt(declarationsItemNoBlanaceRptQueryEntity);
            }
            catch (Exception ex)
            {
                this.lblMsg.Text = ex.Message;
            }
        }

        private void LoadData()
        {
            DeclarationsItemNoBlanaceRptQueryEntity declarationsItemNoBlanaceRptQueryEntity = new DeclarationsItemNoBlanaceRptQueryEntity();
            if (string.IsNullOrEmpty(base.Request.QueryString["from"]))
            {
                if (this.PreviousPage != null)
                {
                    declarationsItemNoBlanaceRptQueryEntity.ItemNoID = this.PreviousPage.ItemNoID;
                    declarationsItemNoBlanaceRptQueryEntity.StartTime = this.PreviousPage.StartTime;
                    declarationsItemNoBlanaceRptQueryEntity.EndTime = this.PreviousPage.EndTime;
                }
                else
                {
                    declarationsItemNoBlanaceRptQueryEntity.ItemNoID = "";
                    declarationsItemNoBlanaceRptQueryEntity.StartTime = "";
                    declarationsItemNoBlanaceRptQueryEntity.EndTime = "";
                }
            }
            else
            {
                this.hdnFrom.Value = base.Request.QueryString["from"].ToString();
            }
            declarationsItemNoBlanaceRptQueryEntity.PageSize = this.gvDeclarationsItemNoBlanaceRptList.PageSize.ToString();
            this.PagerFooter.PageSize = this.gvDeclarationsItemNoBlanaceRptList.PageSize;
            declarationsItemNoBlanaceRptQueryEntity.IsGetAll = false;
            declarationsItemNoBlanaceRptQueryEntity.CurrentPage = "0";
            declarationsItemNoBlanaceRptQueryEntity.SortField = "A.ITEM_NO_ID";
            declarationsItemNoBlanaceRptQueryEntity.SortDirection = "DESC";
            this.SetDeclarationsItemNoBlanaceRptQueryEntity(declarationsItemNoBlanaceRptQueryEntity);
            this.BindData2DeclarationsItemNoBlanaceRpt(declarationsItemNoBlanaceRptQueryEntity);
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!base.IsPostBack)
            {
                base.InitPage(this.Page);
                base.InitAnalyticsReportGridview(this.gvDeclarationsItemNoBlanaceRptList);
                this.LoadData();
            }
        }

        public void SetDeclarationsItemNoBlanaceRptQueryEntity(DeclarationsItemNoBlanaceRptQueryEntity declarationsItemNoBlanaceRptQueryEntity)
        {
            base.PageQueryEntitySession = declarationsItemNoBlanaceRptQueryEntity;
        }

        public DeclarationsItemNoBlanaceRptQuery PreviousPage
        {
            get
            {
                return (DeclarationsItemNoBlanaceRptQuery) base.PreviousPage;
            }
        }
    }
}

